package com.xci.platform.auth.api;

import com.xci.platform.annotation.Authorize;
import com.xci.platform.auth.entity.RoleEntity;
import com.xci.platform.auth.service.RoleService;
import com.xci.platform.controller.BaseController;
import com.xci.platform.core.BoolMessage;
import com.xci.platform.helper.StringHelper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

@Slf4j
@Authorize
@RestController
@RequestMapping("/api/auth/role")
public class RoleApiController extends BaseController {
    /**
     * 角色服务
     */
    @Resource
    private RoleService roleService;

    @PostMapping("/insert")
    public BoolMessage insert(@RequestBody RoleEntity entity){
        return roleService.save(entity,true);
    }

    @PostMapping("/update")
    public BoolMessage update(@RequestBody RoleEntity entity) {
        return roleService.save(entity,false);
    }

    @PostMapping("/delete")
    public BoolMessage delete(@RequestParam String ids) {
        return roleService.delete(StringHelper.splitToArray(ids));
    }

    @PostMapping("/query")
    public BoolMessage query(@RequestParam Map params) {
        return BoolMessage.success(roleService.queryPageList(params));
    }

    /**
     * 获取单个角色详细信息
     *
     * @param id 角色主键
     */
    @PostMapping("/querybyid")
    public BoolMessage queryById(@RequestParam("id") String id) {
        return BoolMessage.success(roleService.queryById(id));
    }

    /**
     * 设置角色启用状态
     */
    @PostMapping("/status")
    public BoolMessage status(String id, Integer status) {
        return roleService.updateStatus(id, status);
    }

    /**
     * 导出角色
     */
    @PostMapping("/export")
    public void export(@RequestParam Map params) {
        //ExcelUtil.exportWeb(response, roleService.queryList(params), RoleEntity.class, "系统角色");
    }
}
